package com.yanu.t2s.controller;

import com.yanu.t2s.entity.Message;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

public class upload {
    @PostMapping("/fu")
    @ResponseBody
    public Message upload(@RequestParam("file") MultipartFile file) {
        Message msg = new Message(200,"文件上传成功！",null);
        if (file.isEmpty()) {
            msg.setCode(502);
            msg.setMsg("请选择文件");
            return  msg;
        }
        String fileName = file.getOriginalFilename();
        String filePath = "d:/";
        File dest = new File(filePath + fileName);
        try {
            file.transferTo(dest);
            System.out.println("ok");

            return  msg;
        } catch (IOException e) {

        }
        msg.setCode(503);
        msg.setMsg("系统原因请重试");
        return  msg ;
    }
}
